# Thanks Michael Nayhouse for this script
# simulation.sh qsub/setup/clean

current_folder=$PWD
for w in 0.2 0.4 0.6 0.8 1.0 1.2 1.4 1.6 1.8 2.0; do
    folder=W$w
    if [ -d $folder ]
        then # Run simulations
        echo "$folder exist"
        cd $folder
        if [ -f simulation.sh ]
            then
            echo "Ready to qsub simulation.sh"
            cat simulation.sh
            echo
            qsub -v LD_LIBRARY_PATH -l h_rt=12:00:00 ./simulation.sh
        else
            echo "Error: simulation.sh not found"
        fi
        cd $current_folder
    else # Create folder and copy simulation.sh to that folder
        echo "Create $folder"
        mkdir $folder
        sed -e "s/VAL_W/$w/g" ./simulation.sh > $folder/temp.sh
        sed -e "s/WORKING_FOLDER/W$w/g" $folder/temp.sh > $folder/simulation.sh
        rm $folder/temp.sh
        chmod 777 $folder/simulation.sh

    fi
done